package com.qo.qsdk.ui.base;

import android.app.Activity;
import android.content.Context;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;

public class Float extends DragViewLayout{

    FloatIconView mFloatView;

    public interface FloatListener {
        void onPay();
        void onCustomer();
        void onClose();
    }

    FloatListener floatListener;

    public void setFloatListener(FloatListener floatListener) {
        this.floatListener = floatListener;
    }

    public Float(Activity context) {
        super(context);
        setClickable(true);

        mFloatView = new FloatIconView(context);
        LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
        addView(mFloatView.getMain(), params);

        setDragListener(new DragListener() {

            @Override
            public void onMove() {
                mFloatView.closeMenu(context);
            }

            @Override
            public void onClick(MotionEvent e) {


                float clickX = e.getRawX(), clickY = e.getRawY();

                int []location = new int[2];
                mFloatView.mLogo.getLocationOnScreen(location);
                float x = location[0];
                float y = location[1];
                if (clickX >= x && clickX <= x + mFloatView.mLogo.getWidth() && clickY >= y && clickY <= y + mFloatView.mLogo.getHeight()) {
                    Log.e("a","logo");
                    mFloatView.toggleMenu(context);
                    return;
                }

                if (mFloatView.mPay.getVisibility() == VISIBLE) {
                    Log.e("a","pay");
                    mFloatView.mPay.getLocationOnScreen(location);
                    x = location[0];
                    y = location[1];
                    if (clickX >= x && clickX <= x + mFloatView.mPay.getWidth() && clickY >= y && clickY <= y + mFloatView.mPay.getHeight()) {
                        if (floatListener != null) floatListener.onPay();
                        mFloatView.closeMenu(context);
                        return;
                    }
                }

                if (mFloatView.mCustomer.getVisibility() == VISIBLE) {
                    Log.e("a","customer");
                    mFloatView.mCustomer.getLocationOnScreen(location);
                    x = location[0];
                    y = location[1];
                    if (clickX >= x && clickX <= x + mFloatView.mCustomer.getWidth() && clickY >= y && clickY <= y + mFloatView.mCustomer.getHeight()) {
                        if (floatListener != null) floatListener.onCustomer();
                        mFloatView.closeMenu(context);
                        return;
                    }
                }

                if (mFloatView.mClose.getVisibility() == VISIBLE) {
                    Log.e("a","close");
                    mFloatView.mClose.getLocationOnScreen(location);
                    x = location[0];
                    y = location[1];
                    if (clickX >= x && clickX <= x + mFloatView.mClose.getWidth() && clickY >= y && clickY <= y + mFloatView.mClose.getHeight()) {
                        if (floatListener != null) floatListener.onClose();
                        mFloatView.closeMenu(context);
                        hide();
                        return;
                    }
                }
            }
        });
    }
}
